package com.team.controller;

import com.team.entity.Admin;
import com.team.service.AdminService;
import com.team.vo.QueryAdminVo;
import com.team.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * -*- coding:utf-8 -*-
 *
 * @author 太阳偷渡青山
 * @software IntelliJ IDEA
 * @date 2022/10/13 20:38
 * @Description
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    /**
     * 添加管理
     *
     * @author 太阳偷渡青山
     * @param admin 管理
     * @return {@link Result}
     */
    @RequestMapping("addAdmin")
    public Result addAdmin(Admin admin){
        return adminService.addAdmin(admin);
    }

    @RequestMapping("toInsert")
    public Result toInsert(@RequestBody Admin admin){
        System.out.println(admin.getPassword());
        return adminService.addAdmin(admin);
    }

    /**
     * 找到所有
     * 找到所有员工根据id
     *
     * @param currentPage  当前页面
     * @param pageSize     页面大小
     * @param queryAdminVo 查询管理签证官
     * @return {@link Result}
     * @author 太阳偷渡青山
     */
    @RequestMapping("list")
    public Result findAll(@RequestParam(defaultValue = "1")Integer currentPage,
                          @RequestParam(defaultValue = "3")Integer pageSize,@RequestBody QueryAdminVo queryAdminVo){

        return adminService.findAll(currentPage,pageSize,queryAdminVo);
    }

    /**
     * 删除一个员工----修改状态码
     *
     * @author 太阳偷渡青山
     * @param id id
     * @return {@link Result}
     */
    @RequestMapping("delete")
    public Result delete(Integer id){
        return adminService.deleteAdmin(id);
    }

    @RequestMapping("update")
    public Result update(@RequestBody Admin admin){
        admin.setUpdateTime(new Date());
        return adminService.updateAdmin(admin);
    }

    @RequestMapping("selectBySectionId")
    public Result selectBySectionId(int sid){
        return adminService.selectBySectionId(sid);
    }

    /**
     * 根据id查询管理员信息
     * @param id
     * @return
     */
    @RequestMapping("selectByid")
    public Result selectByid(int id){
        return adminService.selectByid(id);
    }
}
